//
//  QXHomeDetailsViewController.swift
//  DanTangSwift
//
//  Created by 众力金融 on 2017/6/21.
//  Copyright © 2017年 ..... All rights reserved.
//

import UIKit
import WebKit
import SVProgressHUD

class QXHomeDetailsViewController: QXBaseViewController {
  
    var homeModel : QXHomeTopicModel?
    
    lazy var webView = WKWebView()
    
    override func viewDidLoad() {
        super.viewDidLoad()
          title = "攻略详情"
          setupUI()
    }
}

// MARK: - WKWebView创建
extension QXHomeDetailsViewController {
    func setupUI() {
        webView.frame = view.bounds
        webView.navigationDelegate = self
        guard let urlstr = homeModel?.content_url else { return  }
        let url = URL(string: urlstr)
        let request = URLRequest(url: url!)
        webView.load(request)
        view.addSubview(webView)
    }
}

// MARK: - WKNavigationDelegate
extension QXHomeDetailsViewController : WKNavigationDelegate {
    
    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
        SVProgressHUD.show()
    }
    
    
    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        SVProgressHUD.dismiss()
    }
    
    func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
        SVProgressHUD.dismiss()
    }
}
